/**
 * @(#)HttpProxyRequestLog.java 2016年6月16日
 * Copyright(C) 2015 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package com.zhexinit.proxy.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.jsbd.boss.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import com.google.gson.Gson;

/**
 * http代理请求日志
 * 
 * @author <a href="mailto:zhaihuilin@zhexinit.com" >翟惠林</a>
 * @version 1.0.0
 */
public class HttpProxyLog implements Serializable {
    /**
     * serialVersionUID TODO 请描述这个变量的含义
     */
    private static final long serialVersionUID = -828029758298386057L;
    public static final Logger LOGGER = LoggerFactory.getLogger(HttpProxyLog.class);

    private HttpContext httpContext;
    private String url;
    private Map<String, String> paramMap = new HashMap<String, String>();
    private Map<String, String> headerMap = new HashMap<String, String>();
    private Map<String, String> responseHeaderMap = new HashMap<String, String>();
    private int responseCode;
    private String responseContent;
    private String proxyHost;
    private long connTime;
    private long readTime;
    private String channelCode;
    private byte[] responseContentBytes;
    private String verName;
    private String currentDate;
    /**
     * 用来区分vps代理
     */
    private String ipConnect;

    private Date createTime;

    public HttpProxyLog() {
        createTime = new Date();
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Map<String, String> getParamMap() {
        return paramMap;
    }

    public void setParamMap(Map<String, String> paramMap) {
        this.paramMap = paramMap;
    }

    public Map<String, String> getHeaderMap() {
        return headerMap;
    }

    public void setHeaderMap(Map<String, String> headerMap) {
        this.headerMap = headerMap;
    }

    public Map<String, String> getResponseHeaderMap() {
        return responseHeaderMap;
    }

    public void setResponseHeaderMap(Map<String, String> responseHeaderMap) {
        this.responseHeaderMap = responseHeaderMap;
    }

    public int getResponseCode() {
        return responseCode;
    }

    public void setResponseCode(int responseCode) {
        this.responseCode = responseCode;
    }

    public String getResponseContent() {
        return responseContent;
    }

    public void setResponseContent(String responseContent) {
        this.responseContent = responseContent;
    }

    public long getConnTime() {
        return connTime;
    }

    public void setConnTime(long connTime) {
        this.connTime = connTime;
    }

    public long getReadTime() {
        return readTime;
    }

    public void setReadTime(long readTime) {
        this.readTime = readTime;
    }

    public String getChannelCode() {
        return channelCode;
    }

    public void setChannelCode(String channelCode) {
        this.channelCode = channelCode;
    }

    public String getProxyHost() {
        return proxyHost;
    }

    public void setProxyHost(String proxyHost) {
        this.proxyHost = proxyHost;
    }

    public HttpContext getHttpContext() {
        return httpContext;
    }

    public void cloneAndSetHttpContext(HttpContext httpContext){
        HttpContext httpContext2=new HttpContext();
        BeanUtils.copyProperties(httpContext, httpContext2);
        setHttpContext(httpContext2);
    }
    
    public void setHttpContext(HttpContext httpContext) {
        this.httpContext = httpContext;
    }

    public String getCurrentDate() {
        if (currentDate == null) {
            currentDate = DateUtil.getCurrentDateStr();
        }
        return currentDate;
    }

    public void setCurrentDate(String currentDate) {
        this.currentDate = currentDate;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    public byte[] getResponseContentBytes() {
        return responseContentBytes;
    }

    public void setResponseContentBytes(byte[] responseContentBytes) {
        this.responseContentBytes = responseContentBytes;
    }

    public String getIpConnect() {
        return ipConnect;
    }

    public void setIpConnect(String ipConnect) {
        this.ipConnect = ipConnect;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getParamStr() {
        if (paramMap != null) {
            Gson gson = new Gson();
            return gson.toJson(paramMap);
        }
        return null;
    }

    public String getHeaderStr() {
        if (headerMap != null) {
            Gson gson = new Gson();
            return gson.toJson(headerMap);
        }
        return null;
    }

    public String getRespHeaderStr() {
        if (responseHeaderMap != null) {
            Gson gson = new Gson();
            return gson.toJson(responseHeaderMap);
        }
        return null;
    }

	public String getVerName() {
		return verName;
	}

	public void setVerName(String verName) {
		this.verName = verName;
	}

}
